package 测试;

public class 添加字母成回文串 {

	public static void main(String[] args) {
		String s = "abcd";
		Palindrome q = new Palindrome();
		String addToPalindrome = q.addToPalindrome(s, s.length());
		System.out.println(addToPalindrome);
	}

	public static class Palindrome {
		public String addToPalindrome(String A, int n) {
			String reverse = new StringBuilder(A).reverse().toString();

			int sameCount = 0;// 相同字符数量
			for (int i = 0; i < A.length(); i++) {
				if (A.charAt(i) == reverse.charAt(sameCount)) {
					sameCount++;
				} else {
					if (sameCount > 0)
						i--;
					sameCount = 0;
				}
			}

			return reverse.substring(sameCount);

		}
	}
}
